package logic

import (
	"context"
	"fmt"
	"shenzhou-b/rpc/model/mysql"

	"shenzhou-b/rpc/car"
	"shenzhou-b/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *car.AddGoodsRequest) (*car.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{
		GoodsName:   in.GoodsName,
		GoodsCover:  in.GoodsCover,
		GoodsPrice:  float64(in.GoodsPrice),
		GoodsStock:  in.GoodsStock,
		GoodsStatus: in.GoodsStatus,
	}
	err := g.Create()
	if err != nil {
		logx.Error("发布失败")
		return nil, fmt.Errorf("发布失败")
	}

	return &car.AddGoodsResponse{Success: true}, nil
}
